package com.example.myapp61.xiaoye.top;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapp61.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 课程表适配器
 */
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.Myhoder> {
    private static final String TAG = "测试";
    private Context mContext;
    public ArrayList<ClassBase> mBases;

    public RecyclerViewAdapter(Context context, ArrayList<ClassBase> bases) {
        mContext = context;
        mBases = bases;
        Log.d(TAG, "RecyclerViewAdapter: "+mBases.size());
    }

    @Override
    public int getItemViewType(int position) {
        if ("\uD83D\uDE01\uD83D\uDE01木有课程".equals(mBases.get(position).getName())){
            return 404;
        }
        return super.getItemViewType(position);
    }

    @NonNull
    @Override
    public Myhoder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_recycler_item, null);
        View view2 = LayoutInflater.from(mContext).inflate(R.layout.layout_recycler_item2, null);
        if (viewType==404){
            return new Myhoder(view2);
        }
        return new Myhoder(view);
    }

    @Override
    public void onBindViewHolder(Myhoder holder, int position) {
        holder.textView.setText(mBases.get(position).getName());
        holder.site.setText(mBases.get(position).getSite());
    }

    @Override
    public int getItemCount() {
        return mBases.size();
    }

    class Myhoder extends RecyclerView.ViewHolder {
        private TextView textView,site;
        public Myhoder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.text);
            site = itemView.findViewById(R.id.site);
        }
    }
}
